<?php
namespace App\Api;

use PhalApi\Api;
use App\Domain\Assemble as DomainAssemble;
use PhalApi\Exception\BadRequestException;

/**
 * 拼团相关接口
 */
class Assemble extends Api {
    public function getRules() {
        return array(
            'index' => array(
                'goods_id' => array('name' => 'goods_id', 'require' => true, 'desc' => '商品id'),
            ),
            'detail' => array(
                'user_id' => array('name' => 'user_id', 'require' => true, 'desc' => '用户id'),
                'found_id' => array('name' => 'found_id', 'require' => true, 'desc' => '拼团id'),
                'is_myself' => array('name' => 'is_myself', 'require' => true, 'desc' => '我是否为团长：1是，0不是'),
            ),
        );
    }

    /**
     * 某个商品正在拼团列表
     * @desc 某个商品正在拼团列表
     * @return int found_id 拼团id
     * @return int all_num 拼团总数
     * @return int team_id 拼团活动id
     * @return string nickname 团长用户名昵称
     * @return string head_pic 团长头像
     * @return int join 已参团人数
     * @return int need 需多少人成团
     * @return int few 还需几人参团
     * @return int found_end_time 成团截止时间
     * @return int user_id 开团人id
     */
    public function index() {
        $domain = new DomainAssemble();
        $data = $domain -> getAssembleList( $this->goods_id );
        return $data;
    }

    /**
     * 我参与的拼团详情
     * @desc 我参与的拼团详情
     * @return int found_id 拼团id
     * @return int all_num 拼团总数
     * @return int team_id 拼团活动id
     * @return string nickname 团长用户名昵称
     * @return string head_pic 团长头像
     * @return string follow_user_nickname 团员用户名昵称
     * @return string follow_user_head_pic 团员头像
     * @return int join 已参团人数
     * @return int need 需多少人成团
     * @return int few 还需几人参团
     * @return int goods_id 商品id
     * @return int found_end_time 成团截止时间
     * @return int status 拼团状态0:待开团(表示已下单但是未支付)1:已经开团(团长已支付)2:拼团成功,3拼团失败
     * @return array goods_info 商品信息
     */
    public function detail() {
        $domain = new DomainAssemble();
        $data = $domain -> getAssembleDetail( $this->user_id, $this->found_id, $this->is_myself );
        if( empty( $data ) ){
            throw new BadRequestException('数据获取失败', 1);
        }
        return $data;
    }
}
